package com.transsion.clouddemo.core.Custom

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.transsion.clouddemo.R
import com.transsion.clouddemo.core.ulo.down.DownMessageItem

class BaseInfoAdapter(private val DownList: MutableList<DownMessageItem>) : RecyclerView.Adapter<BaseInfoAdapter.UrlDownViewHolder>() {

    inner class UrlDownViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val successMes: TextView = itemView.findViewById(R.id.url_down_success)
        val failMes: TextView = itemView.findViewById(R.id.url_down_fail)

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UrlDownViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.cloud_url_item, parent, false)
        return UrlDownViewHolder(view)
    }

    @SuppressLint("ResourceAsColor")
    override fun onBindViewHolder(holder: UrlDownViewHolder, position: Int) {
        holder.successMes.text = DownList[position].success
        holder.failMes.text = DownList[position].fail
        if (position == 0) {
            holder.apply {
                successMes.setTextColor(itemView.context.getColor(R.color.cloud_green_prototype))
                failMes.setTextColor(itemView.context.getColor(R.color.cloud_down_fail))
            }
        } else {
            holder.apply {
                successMes.setTextColor(R.color.cloud_text_default)
                failMes.setTextColor(R.color.cloud_text_default)
                successMes.textSize = 12F
                failMes.textSize = 12F
            }
        }

    }
    override fun getItemCount(): Int = DownList.size

}